package com.syy.flow;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
    FlowBean v;
    Text k = new Text();

    @Override
    protected void map(LongWritable longWritable, Text text, Context context)	throws IOException, InterruptedException {
        String s = text.toString();
        String[] split = s.split("\t");
        String phone = split[1];
        long upFlow = Long.parseLong(split[split.length - 3]);
        long downFlow = Long.parseLong(split[split.length - 2]);
        k.set(phone);
        v = new FlowBean(downFlow, upFlow);
        context.write(k, v);
    }
}
